package com.jyw.business.comp.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.jyw.business.comp.domain.CompScheduleShiftTime;
import com.jyw.business.comp.domain.dto.ShiftAddDto;
import com.jyw.business.comp.domain.dto.ShiftEditDto;
import com.jyw.business.comp.domain.vo.CompScheduleShiftQueryVo;
import com.jyw.business.comp.service.ICompScheduleShiftTimeService;
import com.jyw.common.core.domain.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.AjaxResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.business.comp.domain.CompScheduleShift;
import com.jyw.business.comp.service.ICompScheduleShiftService;
import com.jyw.common.utils.poi.ExcelUtil;
import com.jyw.common.core.page.TableDataInfo;

/**
 * 综合-班次Controller
 * 
 * @author ruoyi
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/comp/shift")
@Api(tags = "班次管理")
public class CompScheduleShiftController extends BaseController
{
    @Autowired
    private ICompScheduleShiftService compScheduleShiftService;

    @Resource
    private ICompScheduleShiftTimeService shiftTimeService;

    /**
     * 查询综合-班次列表
     */
    @PreAuthorize("@ss.hasPermi('comp:shift:list')")
    @GetMapping("/list")
    @ApiOperation("班次列表")
    public CommonResult<List<CompScheduleShiftQueryVo>> list()
    {
        List<CompScheduleShift> list = compScheduleShiftService.list();
        List<CompScheduleShiftTime> shiftTimeList = shiftTimeService.list();
        List<CompScheduleShiftQueryVo> result = list.stream().map(data -> {
            CompScheduleShiftQueryVo vo = new CompScheduleShiftQueryVo(data, shiftTimeList);
            return vo;
        }).collect(Collectors.toList());
        return CommonResult.success(result);
    }


    /**
     * 获取综合-班次详细信息
     */
    @PreAuthorize("@ss.hasPermi('comp:shift:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("班次详情")
    public CommonResult<CompScheduleShiftQueryVo> getInfo(@PathVariable("id") Long id)
    {
        CompScheduleShift data = compScheduleShiftService.getById(id);
        List<CompScheduleShiftTime> shiftTimeList = shiftTimeService.lambdaQuery().eq(CompScheduleShiftTime::getShiftId,id).list();
        CompScheduleShiftQueryVo vo = new CompScheduleShiftQueryVo(data, shiftTimeList);
        return CommonResult.success(vo);
    }

    /**
     * 新增综合-班次
     */
    @PreAuthorize("@ss.hasPermi('comp:shift:add')")
    @Log(title = "综合-班次", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增班次")
    public CommonResult add(@RequestBody ShiftAddDto dto)
    {
        compScheduleShiftService.add(dto);
        return CommonResult.success();
    }

    /**
     * 修改综合-班次
     */
    @PreAuthorize("@ss.hasPermi('comp:shift:edit')")
    @Log(title = "综合-班次", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("班次修改")
    public CommonResult edit(@RequestBody ShiftEditDto dto)
    {
        compScheduleShiftService.edit(dto);
        return CommonResult.success();
    }

    /**
     * 删除综合-班次
     */
    @PreAuthorize("@ss.hasPermi('comp:shift:remove')")
    @Log(title = "综合-班次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return CommonResult.success(compScheduleShiftService.deleteCompScheduleShiftByIds(ids));
    }
}
